import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/theme/theme.dart';
import 'package:boss/ui/widget/image/base_image.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class FullOffersRuleItem extends StatefulWidget {
  final VoidCallback onDelete;
  final String initFull;
  final String initLess;
  final ValueChanged<String> onFullChanged;
  final ValueChanged<String> onLessChanged;

  const FullOffersRuleItem({
    Key key,
    this.initFull,
    this.initLess,
    this.onDelete,
    this.onFullChanged,
    this.onLessChanged,
  }) : super(key: key);

  @override
  _FullOffersRuleItemState createState() => _FullOffersRuleItemState();
}

class _FullOffersRuleItemState extends State<FullOffersRuleItem> {
  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: Theme(
        data: lightTheme.copyWith(
          inputDecorationTheme: InputDecorationTheme(
            hintStyle: TextStyleConstant().normal_4_28,
            border: NoInputBorder(),
            enabledBorder: NoInputBorder(),
            focusedBorder: NoInputBorder(),
          ),
        ),
        child: Container(
          margin: EdgeInsets.symmetric(
            horizontal: 55.w,
          ),
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(
                color: ColorConstant.e6e6,
                width: 1.px,
              ),
            ),
          ),
          child: Row(
            children: <Widget>[
              Text('满'),
              _FormField(
                initialValue: widget.initFull,
                onChanged: widget.onFullChanged,
              ),
              Text('元，减'),
              _FormField(
                initialValue: widget.initLess,
                onChanged: widget.onLessChanged,
              ),
              Text('元'),
              Spacer(),
              GestureDetector(
                onTap: widget.onDelete,
                child: BaseImage(
                  'assets/image/delete_icon.png',
                  width: 44.w,
                  height: 44.w,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _FormField extends StatelessWidget {
  final String initialValue;
  final ValueChanged<String> onChanged;

  const _FormField({
    Key key,
    this.onChanged,
    this.initialValue,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: TextFormField(
        keyboardAppearance: Brightness.light,
        initialValue: initialValue,
        onChanged: onChanged,
        textAlign: TextAlign.center,
        decoration: InputDecoration(
            hintText: '请输入金额',
            contentPadding: EdgeInsets.symmetric(
              vertical: 35.w,
            )),
        keyboardType: TextInputType.numberWithOptions(decimal: true),
        inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
      ),
      width: 180.w,
    );
  }
}
